package com.lzy.system.dictManage.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzy.exception.BusException;
import com.lzy.system.dictManage.entity.SysDicGroup;
import com.lzy.system.dictManage.mapper.SysDicGroupMapper;
import com.lzy.system.dictManage.mapper.SysDicValueMapper;
import com.lzy.system.dictManage.service.ISysDicGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 系统字典分组 服务实现类
 * </p>
 *
 * @author lcc
 * @since 2023-12-31
 */
@Service
public class SysDicGroupServiceImpl extends ServiceImpl<SysDicGroupMapper, SysDicGroup> implements ISysDicGroupService {

    private SysDicValueMapper sysDicValueMapper;

    @Autowired
    public SysDicGroupServiceImpl(SysDicValueMapper sysDicValueMapper) {
        this.sysDicValueMapper = sysDicValueMapper;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<String> ids) throws BusException {
        this.removeBatchByIds(ids);
        ids.forEach(id ->sysDicValueMapper.delete(new UpdateWrapper<>(){{
            eq("group_id",id);
        }}));
    }
}
